package top.tenebrous.termbor.rpc.registry;

import top.tenebrous.termbor.rpc.protocol.meta.ServiceMeta;
import top.tenebrous.termbor.rpc.registry.config.RegistryConfig;
import top.tenebrous.termbor.rpc.spi.SPI;

import java.io.IOException;

/**
 * @program: termbor-rpc
 * @description:
 * @author: yazhang6
 * @create: 2024-05-23 09:31
 **/
@SPI
public interface RegistryService {

    /**
     * 服务注册
     * @param serviceMeta  服务元数据
     * @throws Exception
     */
    void register(ServiceMeta serviceMeta) throws Exception;

    /**
     * 服务取消注册
     * @param serviceMeta   服务元数据
     * @throws Exception
     */
    void unRegister(ServiceMeta serviceMeta) throws  Exception;

    /**
     * 服务发现
     * @param serviceName   服务名称
     * @param invokerHashCode   hashcode值
     * @return  服务元数据
     * @throws Exception
     */
    ServiceMeta discovery(String serviceName, int invokerHashCode) throws Exception;

    /**
     * 服务销毁
     * @throws IOException
     */
    void destroy() throws IOException;

    /**
     * 默认初始化
     * @param registryConfig
     * @throws Exception
     */
    default void init(RegistryConfig registryConfig) throws Exception {}
}
